<template>
  <div class="app-container">
    <el-form :model="formData" label-width="120px" label-position="left">
      <el-form-item label="高考状态">
        <el-radio v-model="formData.isTest" label="0">高考前</el-radio>
          <el-radio v-model="formData.isTest" label="1">高考结束</el-radio>
      </el-form-item>
      <el-form-item label="专家分成百分比">
        <el-row>
          <el-col :span="5"><el-input v-model="formData.percent"></el-input></el-col>
          <el-col :span="2"><div class="percent">%</div></el-col>
        </el-row>
      </el-form-item>
    </el-form>
    <div class="submit-box">
      <el-button type="primary" :loading="loading" style="width: 200px;" @click.native.prevent="doSubmit">提交</el-button>
    </div>
  </div>
</template>

<script>
  import { edit, getDetail } from '@/api/site_config'
  import { errorMsg, successMsg } from '@/utils/my'

  export default {
    data() {
      return {
        loading: false,
        formData: {
          id: '1',
          isTest: '',
          percent: ''
        }
      }
    },

    created() {
      this.fetchData()
    },

    methods: {
      fetchData() {
        const that = this
        getDetail({id: that.formData.id}).then(res => {
          that.formData.isTest = res.data.siteConfigIsTest.toString()
          that.formData.percent = res.data.siteConfigPercent.toString()
        })
      },

      doSubmit() {
        const that = this
        let d = that.formData
        that.loading = true
        edit(that.formData).then(res => {
          that.loading = false
          if (res.code != 20000) {
            return errorMsg(res.message)
          }
          successMsg(res.message)
        })
      }
    }
  }
</script>

<style>
  .submit-box {
    height: 50px;
    line-height: 50px;
    text-align: center;
    padding-right: 20px;
  }

  .percent {
    font-size: 18px;
    margin-left: 6px;
  }
</style>
